package common;

import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import user.User;
import user.UserDao;

/**
 * Servlet implementation class ServletJqAjax
 */
@WebServlet("/servletJqAjax")
public class ServletJqAjax extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ServletJqAjax() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	@SuppressWarnings({ "unused", "rawtypes" })
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		// response.getWriter().append("Served at: ").append(request.getContextPath());
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String pass_1 = request.getParameter("paa_1");
		UserDao dao = new UserDao();
		User user = dao.getUserByUname(username);
		String msg="";
		if(username != null){
		      if(user == null){
				    msg="ok";
				    response.setContentType("textml;charset=utf-8");
				    response.getWriter().print(msg);
				    return;
			   }else{
				    msg="该用户已存在";
				    response.setContentType("textml;charset=utf-8");
				    response.getWriter().print(msg);
				    return;
			}
		}else{
		     if(password != null&&pass_1 !=null){
			       if(password.equals(pass_1)){
				   msg="ok";
				   response.setContentType("textml;charset=utf-8");
				   response.getWriter().println(msg);
				   return;
			 }else{
				   msg="密码有误";
				   response.setContentType("textml;charset=utf-8");
				   response.getWriter().println(msg);
				   return;
			       }
		      }
		}
        if (pass_1 != password) {
        	msg = "两次的密码不一致";
            response.setContentType("text/html;charset=utf-8");
   	        response.getWriter().println(msg);
   	        return ;
		}else {
			msg = "ok";
            response.setContentType("text/html;charset=utf-8");
   	        response.getWriter().println(msg);
   	        return ;
		}

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
